//
//  ScoringCell.m
//  Cunli
//
//  Created by lilubin on 15/8/13.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "ScoringCell.h"

@implementation ScoringCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    NSRange range = [_contentStr rangeOfString:@"积分"];
    unichar firstChar = [_contentStr characterAtIndex:range.location-1];
    if (firstChar < '0' || firstChar > '9')
    {
        NSInteger tempLoc = range.location;
        range = [_contentStr rangeOfString:@"积分" options:0 range:NSMakeRange(tempLoc+1, _contentStr.length-tempLoc-1)];
    }
    
    if (range.location != NSNotFound)
    {
        NSUInteger loc = range.location-1;
        NSUInteger newLength = range.length+1;
        NSRange newRange = NSMakeRange(loc, newLength);
        
        unichar numberChar = [_contentStr characterAtIndex:loc];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:_contentStr];
        
        if ((numberChar >='0') && (numberChar <='9'))
        {
            [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:newRange];
            NSUInteger loc2 = loc-1;
            unichar numberChar2 = [_contentStr characterAtIndex:loc2];
            
            if ((numberChar2 >= '0') && (numberChar2 <= '9')) {
                NSRange newRange2 = NSMakeRange(loc2, newLength+1);
                [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:newRange2];
            }
        }
        
        NSRange tempLastRange = [_contentStr rangeOfString:@"积分" options:0 range:NSMakeRange(loc+2, _contentStr.length-loc-2)];
        if (tempLastRange.location != NSNotFound)
        {
            
            NSRange lastRange = NSMakeRange(tempLastRange.location-1, 3);
            unichar numberChar3 = [_contentStr characterAtIndex:lastRange.location];
            if ((numberChar3 >= '0') && (numberChar3 <= '9'))
            {
                [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:lastRange];
            }
            
        }
        
        _contentLabel.attributedText = str;
    }
    else
    {
        _contentLabel.text = _contentStr;
    }
    
}

@end
